// pages/filing/detail.js
const app = getApp()
Page({

    data: {
        fileArr: [],
        haveCar: ["行驶证", "登记证书", "买方身份证原件", "卖方身份证复印件"],
        noCar_entrust: ["买方身份证原件", "卖方身份证复原件"],
        noCar_unentrust: ["验车单", "登记证书", "行驶证", "买方身份证原件", "交易税票", "车牌", "车牌"],
        loading: false
    },

    onLoad: function(options) {
        this.setData(options)
        wx.showLoading({
            title: '请稍等...',
        })
        this.loadData()
    },
    setFileArr() {
        let {
            fileArr = [], type = '', entrustValue = '', entrust=''
        } = this.data

        if (type == "有车") {
            fileArr.push(...this.data.haveCar)
        }
        if (type == "无车" && entrust == "有委托函") {
            fileArr.push(...this.data.noCar_entrust)
        }
        if (type == "无车" && entrust == "无委托函") {
            fileArr.push(...this.data.noCar_unentrust)
        }
        this.setData({
            fileArr
        })
    },
    loadData() {
        app.http.post('rest/archives/view?id=' + this.data.id).then(res => {
            this.setData(res.content)
            this.setFileArr()
            wx.hideLoading()
        }).catch(err => {
            console.log(err)
            app.wxToast.error(err.message)
        })
    },
    payAgain() {

        if (this.data.loading) return
        this.setData({
            loading: true
        })
        wx.showLoading({
            title: '请稍等...',
        })
        app.http.post('rest/archives/pay-again?id=' + this.data.id).then(res => {
            wx.hideLoading()
            this.setData({
                loading: false
            })
            if (res.code == "200") {
                wx.showToast({
                    icon: "none",
                    title: '支付成功',
                })
                this.loadData()
            }else{
                app.wxToast.error(res.msg)
            }
        })
    },
    backindex() {
        const ps = getCurrentPages()
        wx.navigateBack({
            delta: ps.length
        })
    },
})